@Service
public class PlaylistRatingService {
    @Autowired
    private PlaylistRatingRepository playlistRatingRepository;

    public PlaylistRating ratePlaylist(Long userId, Long playlistId, int rating) {
        // 检查用户是否已经评分过该歌单，如果已评分则更新评分，否则创建新的评分记录
        PlaylistRating existingRating = playlistRatingRepository.findByPlaylistIdAndUserId(playlistId, userId);
        if (existingRating != null) {
            existingRating.setRating(rating);
            return playlistRatingRepository.save(existingRating);
        } else {
            PlaylistRating newRating = new PlaylistRating();
            newRating.setUserId(userId);
            newRating.setPlaylistId(playlistId);
            newRating.setRating(rating);
            return playlistRatingRepository.save(newRating);
        }
    }

    // 其他评分相关方法...
}
